/**
 * Created by kangli on 2018/4/17.
 */
var sum;
var counts='';
var pageThis =0;
var pagecount = 5;
var index = 0;
var wheretext = '';

$(function(){
    getcheckList();//得到审核列表

    $(".searchNameInput").keypress(function(e) {
        // 回车键事件
        if(e.which == 13) {
            e.preventDefault();
            getcheckList();
        }
    });

    $(".shai-typeDiv").find("li").click(function(){
        $(".shai-typeDiv").find("li").removeClass("active");
        $(this).addClass("active");
    });
})

function getcheckList(){
    wheretext=$.trim($(".searchNameInput").val());
    var type =   $(".shai-typeDiv").find(".active").text();
    var truetype='';
    if(type=='高校动态'){
        truetype='DYNAMICS'
    }else if(type=='成果展示'){
        truetype='HARVEST'
    }else if(type=='全部'){
        truetype=''
    }else if(type=='专家观点'){
        truetype='OPINION'
    }else if(type=='专题研究'){
        truetype='RESEARCH'
    }else if(type=='会议报告'){
        truetype='REPORT'
    }
    var status = "WAIT_CHECK";
    var  data={page: index ,size: pagecount,title:wheretext,type:truetype,status:status};
    AjaxSubmit("GET",juge(data), basePath + "/super/common/examine/searchSchoolDynamics",searchSchoolDynamics_fun);
}
function searchSchoolDynamics_fun(res){
    //console.log(res);
    if(res.status=='SUCCESS'){
        var checkLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (checkLists.length != 0) {
            $("#checkPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#checkPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                    index = num - 1;
                    getcheckList();
                    pageThis = num;
                }
            });
            $(".checkTbody").empty();
            $('.warnDiv').remove();
            $.each(checkLists, function (i, checkList) {
                  var  statustr = '<span class="texC  cursorP colorBlue" onclick="checkOk(this)" data-id="'+checkList.id+'">通过</span> | <span class="texC  cursorP colorBlue" onclick="checkno(this)">拒绝</span> '
                var type = '';
           /*     var zhaiyao = checkList.abstructContent || '';*/
                var createTime = checkList.creatTime || '';
                var title = checkList.title || '';
                var brief = checkList.brief || '';//摘要？
                if(checkList.type=='DYNAMICS'){
                    type='高校动态'
                }else if(checkList.type=='HARVEST'){
                    type='成果展示'
                }
                var html = '<tr> ' +
                    '<td>'+type+'</td> ' +
                    '<td>'+title+'</td> ' +
                    '<td>'+brief+'</td> ' +
                    '<td>'+createTime+'</td> ' +
                    '<td class="texC"> '+statustr+'| <span class=" cursorP colorBlue" data-id="'+checkList.id+'" onclick="lookdetail(this)">详情</span></td> ' +
                    '</tr>';
                $(".checkTbody").append(html)
            })

        }
        else{
            $("#checkPage").css("display","none");
            $(".checkTbody").empty();
            $('.warnDiv').remove();
            var html = $('<div class="text-center warnDiv "  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".checkTable").after(html)
        }
    }
}

//审核通过
function checkOk(btn){
    var msg = "您确定通过吗？\n\n请确认！";
    if (confirm(msg)==true){
        var newsId = $(btn).attr("data-id");
        var  data={id: newsId,schoolDynamicsStatusEnum:'AUDITED'};
        AjaxSubmit("POST",data, basePath + "/super/common/examine/changeStatusByType",changeStatusByType_fun);
        function changeStatusByType_fun(res){
            if(res.status=='SUCCESS'){
                index=$("#checkPage").find(".active").find("a").text()-1;
                getcheckList();
            }
        }
    }else{
        return false;
    }
}
//审核拒绝
function checkno(btn){
    var msg = "您确定拒绝吗？\n\n请确认！";
    if (confirm(msg)==true){
        var newsId = $(btn).attr("data-id");
         var  data={id: newsId,schoolDynamicsStatusEnum:'REJECT'};
         AjaxSubmit("POST",data, basePath + "/super/common/examine/changeStatusByType",changeStatusByType_fun);
         function changeStatusByType_fun(res){
             if(res.status=='SUCCESS'){
             index=$("#checkPage").find(".active").find("a").text()-1;
             getcheckList();
             }
         }
    }else{
        return false;
    }
}
//查看高校具体信息详情
function lookdetail(btn){
    var schoolDynamicsId = $(btn).attr("data-id");
    window.parent.open("exchangeDetail.html?schoolDynamicsId="+schoolDynamicsId);
}

//判断字符不空就存
function juge(obj){
    var result={};
    for(i in obj){
        if(obj[i]==null||obj[i]==""){
            continue;
        }
        var value=obj[i];
        eval("result."+i+"='"+value+"'");
    }
    return result;
}